package com.group.entity;


import com.group.entity.user.UserAccountEntity;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

public class LoginUser implements UserDetails {

    private UserAccountEntity userAccountEntity;

    public LoginUser(UserAccountEntity userAccountEntity) {
        this.userAccountEntity = userAccountEntity;
    }

    public LoginUser(UserAccountEntity userAccountEntity, List<String> list) {
        this.userAccountEntity = userAccountEntity;
        this.list = list;
    }

    public LoginUser() {
    }

    private List<String> list;
    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {

        //权限信息
        List<SimpleGrantedAuthority> grantedAuthorities  = new ArrayList<>();
        if (list!=null&&list.size()>=1){

            for (String s : list) {
                if (s!=null&&!s.equals("")){
                    grantedAuthorities.add(new SimpleGrantedAuthority(s));
                }
            }
        }
        return grantedAuthorities;
    }

    @Override
    public String getPassword() {
        return userAccountEntity.getUserPassword();
    }

    @Override
    public String getUsername() {
        return userAccountEntity.getUserName();
    }

    /**
     * 是否过期
     * @return
     */
    @Override
    public boolean isAccountNonExpired() {
        return true;
    }

    /**
     * 是否锁定
     * @return
     */
    @Override
    public boolean isAccountNonLocked() {
        return true;
    }

    /**
     *凭证是否过期
     * @return
     */
    @Override
    public boolean isCredentialsNonExpired() {
        return true;
    }

    /**
     *是否可用
     * @return
     */
    @Override
    public boolean isEnabled() {
        return true;
    }

    public UserAccountEntity getUserAccountEntity() {
        return userAccountEntity;
    }

    public void setUserAccountEntity(UserAccountEntity userAccountEntity) {
        this.userAccountEntity = userAccountEntity;
    }

    public List<String> getList() {
        return list;
    }

    public void setList(List<String> list) {
        this.list = list;
    }
}
